package com.ny.demo517;

import com.ny.demo516.Emp;

import java.util.ArrayList;
import java.util.List;

public class TestList {
    //1.添加员工的功能
    public void addEmp(List<Emp> list, Emp emp) {
        list.add(emp);
    }

    //2.查询所有的员工信息
    public void finfAllEmp(List<Emp> list) {
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }

    //3.根据姓名进行查询员工信息
    public Emp findEmpName(List<Emp> list, String ename) {
        for (int i = 0; i < list.size(); i++) {
            if (ename.equals(list.get(i).getName())) {
                return list.get(i);
            }
        }
        return null;
    }

    //4.根据员工编号删除某个员工的信息
    public void deleteEmpNumber(List<Emp> list, String number) {
        for (int i = 0; i < list.size(); i++) {
            if (number.equals(list.get(i).getNumber())) {
                list.remove(i);
                System.out.println(list);
            }
        }
    }
//    5 根据员工编号查询员工的信息
public Emp findEmpNumber(List<Emp> list, String number) {
    for (int i = 0; i < list.size(); i++) {
        if (number.equals(list.get(i).getNumber())) {
            return list.get(i);
        }
    }
    return null;
}


//    6 根据员工编号修改某个员工的信息 比如 1001 的年龄修改为20
    public void updateEmpAge(List<Emp> list,Emp emp){
        for (int i = 0; i < list.size(); i++) {
            if (emp.getNumber().equals(list.get(i).getNumber())) {
                list.set(i,emp);

                System.out.println(list);
            }
        }
    }

}
